﻿using MediatR;
using T_Person.BaseRep.Interface;
using T_Person.Read.APi.Applaction.Command;
using T_Person.Read.APi.Dto;

namespace T_Person.Read.APi.Applaction.CommandHandlers
{
    public class EmployeeSearchByNameandStateHandlers : IRequestHandler<EmployeeSearchByNameandStatewords, List<PublicArray>>
    {
        private readonly IEmployeeRep employeeRep;

        public EmployeeSearchByNameandStateHandlers(IEmployeeRep employeeRep)
        {
            this.employeeRep = employeeRep;
        }

        public async Task<List<PublicArray>> Handle(EmployeeSearchByNameandStatewords request, CancellationToken cancellationToken)
        {
            var list = await employeeRep.GetvaluesByResult(x => x.IsDel == false && x.EmployeeStyle == request.state && x.DepartId == request.dname);
            var lista=new List<PublicArray>();
            foreach (var item in list)
            {
                lista.Add(new PublicArray
                {
                    id = item.Eid,
                    name = item.Ename
                });
            }
            return await Task.FromResult(lista);

        }
    }
}
